package com.kaikeba.t31.core.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kaikeba.t31.core.dao.ICrudDao;
import com.kaikeba.t31.core.po.BaseEntity;
import com.kaikeba.t31.core.service.ICrudService;

import java.util.List;

/**
 * Service实现类基类
 * 因为Mybatis Plus ServiceImpl没有分页查询
 * - listPage：分页查询
 * - list：查询所有
 *
 * @author Cui Yicheng
 * @since 2021/11/06
 */
public class CrudServiceImpl<T extends BaseEntity> extends ServiceImpl<ICrudDao<T>, T> implements ICrudService<T> {

    @Override
    public PageInfo<T> listPage(T entity, int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> {
            baseMapper.selectByQuery(entity);
        });
    }

    @Override
    public List<T> list(T entity) {
        return baseMapper.selectByQuery(entity);
    }

}
